
/* VISUALLINX Execute(Alias:V_MR_60A_TEMP)  */
					SELECT
						DATA_FISCAL		=	CONVERT(VARCHAR, LCF.DATA_FISCAL, 112),
						ID_EQUIPAMENTO	=	CONVERT(CHAR(20), LCF.ID_EQUIPAMENTO),
						LCF.TOTAL_SUBSTITUICAO, TOTAL_ISENTO, TOTAL_NAO_TRIBUTAVEL, TOTAL_CANCELADO, TOTAL_DESCONTO,
						TOTAL_ISS = ISNULL((SELECT SUM(VALOR_IMPOSTO) FROM LOJA_CONTROLE_FISCAL_TARIFAS Z
											WHERE	Z.CODIGO_FILIAL = LCFT.CODIGO_FILIAL
												AND Z.TERMINAL = LCFT.TERMINAL
												AND Z.DATA_FISCAL = LCFT.DATA_FISCAL
												AND Z.ECF = LCFT.ECF
												AND Z.ID_EQUIPAMENTO = LCFT.ID_EQUIPAMENTO
												AND Z.SERIE_NF = LCFT.SERIE_NF
												AND Z.CF_INICIAL = LCFT.CF_INICIAL
												AND Z.LEGENDA_TARIFA = LCFT.LEGENDA_TARIFA
												AND Z.ID_IMPOSTO IN (14, 22)), 0.00),
						LCFT.TOTAL_TARIFA, LCFT.PER_TARIFA
					FROM LOJA_CONTROLE_FISCAL AS LCF (NOLOCK)
						JOIN LOJA_CONTROLE_FISCAL_TARIFAS AS LCFT (NOLOCK)
							ON (LCF.CODIGO_FILIAL = LCFT.CODIGO_FILIAL
							AND LCF.TERMINAL = LCFT.TERMINAL
							AND LCF.DATA_FISCAL = LCFT.DATA_FISCAL
							AND LCF.ECF = LCFT.ECF
							AND LCF.ID_EQUIPAMENTO = LCFT.ID_EQUIPAMENTO
							AND LCF.CF_INICIAL = LCFT.CF_INICIAL
							AND LCF.SERIE_NF = LCFT.SERIE_NF)
						JOIN CADASTRO_CLI_FOR AS FIL (NOLOCK)
							ON (LCF.FILIAL = FIL.NOME_CLIFOR)
						JOIN FILIAIS (NOLOCK)
							ON (FILIAIS.FILIAL = FIL.NOME_CLIFOR)
						LEFT JOIN SERIES_NF AS S
							ON LCF.SERIE_NF = S.SERIE_NF
						LEFT JOIN CTB_ESPECIE_SERIE ES (NOLOCK)
							ON (S.ESPECIE_SERIE = ES.ESPECIE_SERIE)
								where	LCFT.ID_IMPOSTO = 1
					AND LCF.ECF <> 0
					AND LCFT.VALOR_OUTROS + LCFT.VALOR_ISENTO = 0
					AND LCFT.TOTAL_TARIFA <> 0
					AND ES.NUMERO_MODELO_FISCAL = CASE WHEN ISNUMERIC(ES.NUMERO_MODELO_FISCAL) = 1 THEN '02' ELSE '2D' END
					AND LCF.SERIE_NF <> 'D1' AND  FILIAIS.MATRIZ_FISCAL = '1'  AND   LCF.DATA_FISCAL BETWEEN '20090801' AND '20090831'
					ORDER BY LCF.DATA_FISCAL, LCF.ID_EQUIPAMENTO